﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Member.BasePage;

namespace Member.Web.Api
{
    public partial class Default : BasePage.BasePage
    {
        bool ret;
        string msg;

        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request["action"].ToString();
            switch (action)
            {
                case "login":
                    login();
                    break;
                case "ChangeStatus":
                    ChangeStatus();
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 登陆
        /// </summary>
        protected void login()
        {
            string Name = Request["name"].ToString();
            string Passwd = Request["passwd"].ToString();
            Passwd = Member.Common.Common.Md5(Passwd);
            string html = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><content>";
            if (__bll_user.Exists(Name, Passwd))
            {
                __model_user = __bll_user.GetModel(Name);
                if (__model_user.Status == 0)
                {
                    if (__model_user.Type >= 1)
                    {
                        if (__model_user.EndTiem > DateTime.Now)
                        {
                            html += "<ID>" + __model_user.ID + "</ID>";
                            html += "<Name>" + __model_user.Name + "</Name>";
                            html += "<Passwd>" + __model_user.Passwd + "</Passwd>";
                            html += "<Email>" + __model_user.Email + "</Email>";
                            html += "<Phone>" + __model_user.Phone + "</Phone>";
                            html += "<Type>" + __model_user.Type + "</Type>";
                            html += "<Product>" + __model_user.Product + "</Product>";
                            html += "<RegTime>" + __model_user.RegTime + "</RegTime>";
                            html += "<RegIP>" + __model_user.RegIP + "</RegIP>";
                            html += "<LoginTime>" + __model_user.LoginTime + "</LoginTime>";
                            html += "<LoginIp>" + __model_user.LoginIp + "</LoginIp>";
                            html += "<Session>" + __model_user.Session + "</Session>";
                            html += "<PicTure>" + __model_user.PicTure + "</PicTure>";
                            html += "<StartTime>" + __model_user.StartTime + "</StartTime>";
                            html += "<EndTiem>" + __model_user.EndTiem + "</EndTiem>";
                            html += "<Status>" + __model_user.Status + "</Status>";
                            ret = true;
                            msg = "登陆成功";
                        }
                        else { ret = false; msg = "会员已到期!"; }
                    }
                    else
                    {
                        ret = false;
                        msg = "受限会员,无法登陆!";
                    }
                }
                else
                {
                    ret = false;
                    msg = "已经在线!";
                }
            }
            else { ret = false; msg = "密码错误或用户名不存在!"; }
            html += "<return>" + ret.ToString() + "</return><msg>" + msg + "</msg>";
            html += "</content>";
            Response.Write(html);
        }
        /// <summary>
        /// 更改状态
        /// </summary>
        protected void ChangeStatus()
        {
            string Name = Request["name"];
            int status = Convert.ToInt32(Request["status"].ToString());
            __bll_user.UpdateStatus(Name, status);
        }
    //登陆
    }
}